import { defineStore } from "pinia";
import axios from "axios";
import { ChannelRes, ChannelList } from "../../types/data";

const useChannelStore = defineStore("Channel", {
  state() {
    return {
      list: [] as ChannelList,
      active: -1,
    };
  },
  actions: {
    async getChannelList() {
      const res = await axios.get<ChannelRes>(
        "http://geek.itheima.net/v1_0/channels"
      );
      this.list = res.data.data.channels;
      this.active = res.data.data.channels[0].id;
    },
    changeActive(id: number) {
      this.active = id;
    },
  },
  getters: {},
});

export default useChannelStore;
